<template>
    <Card>
        <Row>
            <Col span="24">
                <Card>
                    <span style="font-size: 14px;color:#1c2438;font-weight: 700;">欺诈检核过滤结果：</span>
                    <Button type="primary" style="float:right" @click="refreshCheckData" v-if="taskParams.isModal==false">检核过滤结果刷新</Button>
                </Card>
                <Table :columns="columns1" :data="pageList.data"></Table>
                <div style="margin: 10px;overflow: hidden">
                    <div style="float: right;">
                        <Page :total="pageList.dataTotal" :current="pageList.pageNo" :page-size="pageList.pageSize" @on-change="changeTrickCheckInfoPage"></Page>
                    </div>
                </div>
            </Col>
        </Row>
        <br>
        <Row>
            <Col span="24">
            <Card>
                <p slot="title">风险检核过滤结果：</p>
                <Table :columns="columns2" :data="pageList2.data"></Table>
                <div style="margin: 10px;overflow: hidden">
                    <div style="float: right;">
                        <Page :total="pageList2.dataTotal" :current="pageList2.pageNo" :page-size="pageList2.pageSize" @on-change="changeRiskCheckInfoPage"></Page>
                    </div>
                </div>
            </Card>
            </Col>
        </Row>
        <br>
        <Row>
            <Col span="24">
            <Card>
                <p slot="title">历史任务：</p>
                <Table :columns="columns3" :data="pageList3.data"></Table>
                <div style="margin: 10px;overflow: hidden">
                    <div style="float: right;">
                        <Page :total="pageList3.dataTotal" :current="pageList3.pageNo" :page-size="pageList3.pageSize" @on-change="changeHistoryLoanInfoPage"></Page>
                    </div>
                </div>
            </Card>
            </Col>
        </Row>
    </Card>
</template>

<script>
export default {
  name: 'cross-check-form',
  data () {
    return {
      baseUrl: this.$appContext.marvels_core_approve,
      $ajax: null,
      columns1: [
        {
          align: 'center',
          title: '申请字段',
          key: 'applyColumn'
        },
        {
          align: 'center',
          title: '欺诈字段',
          key: 'fakeColumn'
        },
        {
          align: 'center',
          title: '匹配内容',
          key: 'matchField'
        },
        {
          align: 'center',
          title: '操作',
          width: 80,
          key: 'action'
        }
      ],
      pageList: {
        data: [],
        dataTotal: 0,
        pageTotal: 1,
        pageNo: 1,
        pageSize: 5
      },
      columns2: [
        {
          align: 'center',
          title: '申请字段',
          key: 'applyColumn'
        },
        {
          align: 'center',
          title: '匹配申请编号',
          key: 'matchApplyNo'
        },
        {
          align: 'center',
          title: '匹配来源',
          key: 'matchSource'
        },
        {
          align: 'center',
          title: '字段名称',
          key: 'columnName'
        },
        {
          align: 'center',
          title: '匹配内容',
          key: 'matchText'
        },
        {
          align: 'center',
          title: '代码',
          key: 'matchCode'
        },
        {
          align: 'center',
          title: '操作',
          width: 80,
          key: 'action',
          render: (h, params) => {
            var vm = this
            return h('div', [
              h('Button', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                on: {
                  click: () => {
                    vm.openModal(params.row.matchApplyNo)
                  }
                }
              }, ' 查看')
            ])
          }
        }
      ],
      pageList2: {
        data: [],
        dataTotal: 0,
        pageTotal: 1,
        pageNo: 1,
        pageSize: 5
      },
      columns3: [
        {
          align: 'center',
          title: '受理号',
          key: 'loanId',
          render: function (h, params) {
            const vm = this
            return h('div', {
              on: {
                click () {
                  vm.openModal(params.row.loanId)
                }
              },
              style: {
                'color': '#20a0ff',
                'cursor': 'pointer'
              }
            }, params.row.loanId)
          }.bind(this)
        },
        {
          align: 'center',
          title: '客户姓名',
          key: 'custName'
        },
        {
          align: 'center',
          title: '子业务类型',
          key: 'productTypeName'
        },
        {
          align: 'center',
          title: '工单状态',
          key: 'statusName'
        }
      ],
      pageList3: {
        data: [],
        dataTotal: 0,
        pageTotal: 1,
        pageNo: 1,
        pageSize: 10
      },
      refreshCheckDataKey: 'crossCheckForm_disable_btn_'
    }
  },
  methods: {
    // 页面初始化
    init () {
      this.loadTrickCheckInfoPageData()
      this.loadRiskCheckInfoPageData()
      this.loadHistoryLoanInfoPageData()
    },
    // 加载欺诈检核过滤结果数据
    loadTrickCheckInfoPageData () {
      var vm = this
      var url = this.baseUrl + 'approve/process/task_process/service/geTrickCheckInfoPage/' + this.pageList.pageNo + '/' + this.pageList.pageSize
      var params = { loanId: this.taskParams.curLoanId }
      this.$ajax.post(url, params).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
          return
        }
        vm.pageList.data = data.data.list
        vm.pageList.dataTotal = data.data.total
        vm.pageList.pageTotal = data.data.pages
      }).catch(er => {

      })
    },
    // 加载风险检核过滤结果数据
    loadRiskCheckInfoPageData () {
      var vm = this
      var url = this.baseUrl + 'approve/process/task_process/service/getRiskCheckInfoPage/' + this.pageList2.pageNo + '/' + this.pageList2.pageSize
      var params = { loanId: this.taskParams.curLoanId }
      this.$ajax.post(url, params).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
          return
        }
        vm.pageList2.data = data.data.list
        vm.pageList2.dataTotal = data.data.total
        vm.pageList2.pageTotal = data.data.pages
      }).catch(er => {

      })
    },
    // 加载历史任务数据
    loadHistoryLoanInfoPageData () {
      var vm = this
      var url = this.baseUrl + 'approve/process/task_process/service/getHistoryLoanInfoPage/' + this.pageList3.pageNo + '/' + this.pageList3.pageSize
      var params = { custCardNo: this.taskParams.custCardNo, loanId: this.taskParams.curLoanId }
      this.$ajax.post(url, params).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
          return
        }
        vm.pageList3.data = data.data.list
        vm.pageList3.dataTotal = data.data.total
        vm.pageList3.pageTotal = data.data.pages
      }).catch(er => {

      })
    },
    // 翻页 欺诈检核过滤结果
    changeTrickCheckInfoPage (index) {
      this.pageList.pageNo = index
      this.loadTrickCheckInfoPageData()
    },
    // 翻页 风险检核过滤结果
    changeRiskCheckInfoPage (index) {
      this.pageList2.pageNo = index
      this.loadRiskCheckInfoPageData()
    },
    // 翻页 历史任务
    changeHistoryLoanInfoPage (index) {
      this.pageList3.pageNo = index
      this.loadHistoryLoanInfoPageData()
    },
    // 刷新检核过滤结果
    refreshCheckData () {
      if (this.computeDisable()) {
        this.$Message.warning('请60s后再试')
        return
      }
      var vm = this
      var loanId = this.taskParams.curLoanId
      this.$ajax.post(this.baseUrl + 'approve/process/task_process/service/updateTrickAndRiskCheckData/' + loanId).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
          return
        }
        // vm.changeTrickCheckInfoPage(1)
        // vm.changeRiskCheckInfoPage(1)
        // this.$Message.success(message)
        let now = new Date()
        let disableTime = new Date().setMinutes(now.getMinutes() + 1)
        localStorage[vm.refreshCheckDataKey + loanId] = disableTime
        alert('检核结果开始更新，请几分钟后查看')
      }).catch(er => {

      })
    },
    computeDisable () {
      var v = localStorage[this.refreshCheckDataKey + this.taskParams.curLoanId]
      if (!v || v == null || v === '') {
        return false
      }
      if (v - new Date() > 0) {
        return true
      } else {
        return false
      }
    },
    // 查看
    openModal (loanId) {
      this.$emit('on-item-check', loanId)
    }
  },
  computed: {

  },
  mounted () {

  },
  created () {
    this.$ajax = this.$util.ajax()
  },
  watch: {
    'taskParams.crossCheck' (v) {
      if (v) {
        this.init()
      }
    }
  },
  props: {
    taskParams: Object
  }
}
</script>
